package com.mproject.adapter;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.mproject.activity.R;
import com.mproject.activity.project.Project_Info;
import com.mproject.customclass.Student;
import com.mproject.customclass.UserAdded;


public class Member_List_Adapter extends ArrayAdapter<Student>{

	private static final String tag = "Add_Member_Added_List_Adapter";

	// private static final String ASSETS_DIR = "images/";
	private Context context;
	Project_Info activity;

	private TextView member_name;
	private TextView member_user_id;
	private TextView member_cuurent_user;
	private TextView member_manager;

	private List<Student> userList = new ArrayList<Student>();
	public Member_List_Adapter(Project_Info activity,Context context, int textViewResourceId,List<Student> userList)
	{
		super(context, textViewResourceId, userList);
		this.context = context;
		this.userList = userList;
		this.activity=activity;
		Log.v(tag,"in constructor");
	}
	public int getCount() 
	{
		return this.userList.size();
	}
	public Student getItem(int index) 
	{
		return this.userList.get(index);
	}
	public View getView(final int position, View convertView, ViewGroup parent) 
	{
		View row = convertView;
		if (row == null) 
		{
			Log.d(tag, "Starting XML Row Inflation ... ");
			LayoutInflater inflater = (LayoutInflater) this.getContext()
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			row = inflater.inflate(R.layout.member_list_row, parent, false);
			Log.d(tag, "Successfully completed XML Row Inflation!");
		}

		final Student user = getItem(position);


		member_name = (TextView) row.findViewById(R.id.member_name);
		member_user_id = (TextView) row.findViewById(R.id.member_user_id);
		member_cuurent_user = (TextView)row.findViewById(R.id.member_current_user);
		member_manager = (TextView) row.findViewById(R.id.member_manager);

		if (user.isManager()) {
			member_manager.setVisibility(View.VISIBLE);
		}
		else {
			member_manager.setVisibility(View.GONE);
		}
		if (user.isCurrentUser()) {
			member_cuurent_user.setVisibility(View.VISIBLE);
		}
		else {
			member_cuurent_user.setVisibility(View.GONE);
		}


		member_user_id.setText(user.getUserID());
		member_name.setText(user.getName());

		return row;
	}

}

